﻿/*
* Activity Tracking Log v0.1.1 - http://activitytrackinglog.codeplex.com
* Activity Tracking Log for ASP.Net & ASP.Net MVC
* Copyright (c) 2011 Vadim Burac
* Licensed under the Microsoft Public License (Ms-PL)
* http://activitytrackinglog.codeplex.com/license
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;

namespace ActivityTrackingLog.Configuration.ConfigSections
{
    public class StorageConfigSection : BaseConfigSection
    {
        #region properties

        #endregion

        #region config accessors

        [ConfigurationProperty("type", IsRequired = false)]
        public string Type
        {
            get
            {
                return GetConfigValue("type", string.Empty);
            }
        }

        [ConfigurationProperty("connectionString", IsRequired = false)]
        public virtual string ConnectionString
        {
            get 
            {
                return GetConfigValue("connectionString", string.Empty);
            }
        }

        [ConfigurationProperty("oldestDate", IsRequired = false)]
        public DateTime? OldestDate
        {
            get
            {
                return GetConfigValue<DateTime?>("oldestDate", null);
            }

        }

        [ConfigurationProperty("recordsLimit", IsRequired = false)]
        public int? RecordsLimit
        {
            get
            {
                return GetConfigValue<int?>("recordsLimit", null);
            }
        }

        #endregion

        #region helpers

        public override string ToString()
        {
            return string.Format("{0}, {1}",
                base.ToString(),
                string.Format("Type: {0}, ConnectionString: {1}, OldestDate: {2}, RecordsLimit: {3}",
                    Type,
                    string.IsNullOrWhiteSpace(ConnectionString)?"[Not defined]":"[Defined]",
                    OldestDate.HasValue?OldestDate.Value.ToString():"[Not defined]",
                    RecordsLimit.HasValue ? RecordsLimit.Value.ToString() : "[Not defined]"));
        }

        #endregion
    }
}
